<template>
  <div class="activity-wrap">
    <h2>活动管理</h2>
    <div class="activity-list">
      <el-table :data="activityList" style="width: 100%" v-loading="loading">
        <el-table-column prop="activity_name" label="活动名称" width="180">
        </el-table-column>
        <el-table-column prop="created_at" label="创建时间" width="180">
        </el-table-column>
        <el-table-column prop="state" label="状态"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
              >审核</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.row.activity_id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        layout="prev, pager, next"
        :total="totalCount"
        @current-change="currentChange"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
// @ 符号代表项目的根路径下 src，即
// import {
//   getActivityList,
//   getActivityTotal,
//   delActivityApi,
// } from "@/http/activityApi";

export default {
  name: "ActivityView",
  data() {
    return {
      activityList: [],
      currentPage: 1,
      pageSize: 10,
      totalCount: 0,
      loading: false,
    };
  },
  created() {
    this.getInit(this.currentPage, this.pageSize);
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
      console.log("你正在操作的item是：", row.activity_id);
    },
    handleDelete(id) {
      console.log("删除id:", id);

      this.$confirm("此操作将永久删除该数据, 是否继续?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "error",
      })
        .then(() => {
          console.log("确认");
          this.delActivity(id);
        })
        .catch(() => {
          console.log("取消");
        });
    },
    delActivity(id) {
      console.log(id);
      // delActivityApi(id).then().catch();
    },
    getInit(currentPage, pageSize) {
      console.log(currentPage, pageSize);
      // this.loading = true;
      // getActivityTotal()
      //   .then((res) => {
      //     this.totalCount = res.data.data;
      //   })
      //   .catch((err) => {
      //     console.log("获取总数量失败：", err);
      //   });
      // getActivityList(currentPage, pageSize)
      //   .then((res) => {
      //     this.activityList = res.data.data;
      //     this.loading = false;
      //   })
      //   .catch((err) => {
      //     console.log("获取列表失败：", err);
      //   });
    },
    currentChange(currentPage) {
      console.log("当前页", currentPage);
      this.currentPage = currentPage;
      this.getInit(currentPage, this.pageSize);
    },
  },
};
</script>